package cn.ichiva.wall_street.api;

import cn.ichiva.common.web.R;
import cn.ichiva.wall_street.api.vo.StockVO;
import cn.ichiva.wall_street.domian.PredictRes;
import cn.ichiva.wall_street.service.AgentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

@Api(value = "home",tags = "主页")
@RestController
@RequestMapping("/home")
@CrossOrigin
public class HomeController {

    @Autowired
    AgentService agentService;

    @ApiOperation("可预测股票列表")
    @GetMapping("/stockList")
    public R<Collection<StockVO>> stockList(){
        Collection<StockVO> list = agentService.list();
        return R.ok(list);
    }

    /**
     * 操作记录
     *
     * @param ts_code 股票代码
     * @param skip 跳过记录数
     * @param size 可选集合尺寸默认10
     * @return
     */
    @ApiOperation("操作记录")
    @GetMapping("/decisions/{ts_code}/{skip}")
    public R<List<String>> decisionsForDetails(@PathVariable String ts_code,
                                               @PathVariable int skip,
                                               @RequestParam(defaultValue = "10") int size){
        List<String> list = agentService.getOperationRecord(ts_code,skip,size);
        return R.ok(list);
    }

    @ApiOperation("最后预测结果")
    @GetMapping("/predictRes/{ts_code}")
    public R<PredictRes> getPredictRes(@PathVariable String ts_code){
        return R.ok(agentService.predictRes(ts_code));
    }



    @ApiOperation("订阅/取消订阅,在email前加'-'表示取消订阅")
    @GetMapping("/subscribe")
    public R<Boolean> subscribe(String ts_code,String mail){
        return R.ok(agentService.subscribe(ts_code,mail));
    }
}
